#include "context.h"

string Context :: select_state (Parser parser,unsigned short a, string b) 
{  
    vector <int> aux(2); 
    parser.getInitPos(aux,state->id,state->path);

    if (parser.goal || parser.half_time)
    {
        if(parser.kick_off){
            state=new Searchingball();
        }
        else
            state=new Initposition();

    }

    else if( (state->id>5 && state->id<12) &&(state->moved==false)){ 
		   if(!parser.objectball)
			state=new Searchingball(); 
		   else {			
			state=new Defend(); 
			}
	}

    else if(parser.objectball)
    {
         if (parser.ball[0]>1 ){
                state= new Runtoball();
            }
         else if (parser.ball[0]<=1 &&  parser.ball[0]>0){
		if (parser.kick_in)
		    state= new Kickin(); 
                else if(parser.theirgoal[0]>20)
                    state= new Runwithball();
		else if (parser.mygoal[0]<25 && parser.mygoal[0]>0)
			state=new Defend(); 
                else{
                    state=new Kicktogoal();
		}
            }

        else
            state=new Searchingball();
    }

    else 
	state=new Searchingball();

   
    state->setParams(a, b);
    state->output.str("");
    return state->command(parser);
    delete state;
}
